package com.zhuangjie.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuangjie.order.entity.OrderDetail;
import com.zhuangjie.order.enums.OrderState;
import com.zhuangjie.order.mapper.OrderDetailMapper;
import com.zhuangjie.order.pojo.DishSalesCount;
import com.zhuangjie.order.service.OrderDetailService;
import com.zhuangjie.order.vo.OrderDetailForEvaluate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 订单明细表 服务实现类
 * </p>
 *
 * @author zhuangjie
 * @since 2023-11-24
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService {


    @Override
    public List<OrderDetailForEvaluate> getOrderDetailForEvaluateListByOrderId(Long orderId) {
        return this.baseMapper.getOrderDetailForEvaluateListByOrderId(orderId);
    }

    @Override
    public List<OrderDetail> getOrderDetailByOrderId(Long orderId) {
        LambdaQueryWrapper<OrderDetail> queryOrderDetailWrapper = Wrappers.lambdaQuery(OrderDetail.class)
                .eq(OrderDetail::getOrderId, orderId);
        List<OrderDetail> list = this.list(queryOrderDetailWrapper);
        return list == null? new ArrayList<>():list;
    }

    @Override
    public List<DishSalesCount> getShopDishSalesCount(Long shopId, Integer nDaysAgo) {
        return this.baseMapper.getShopDishSalesCount(shopId, LocalDateTime.now().minusDays(nDaysAgo), OrderState.getCompletedEndPoints());
    }
}
